/// Converts a decimal number to a string representation in the specified base
///
/// # Parameters
/// - `num` - The decimal number to convert
/// - `base` - The target base
///
/// # Returns
/// Returns the string representation in the specified base
fn convert_to_base(mut num: u32, base: u32) -> String {
    let mut result = String::new();
    let digits = "0123456789abcdef";

    // Process the number until it becomes 0
    while num > 0 {
        let remainder = (num % base) as usize;
        result.push(digits.chars().nth(remainder).unwrap());
        num /= base;
    }

    // If the result is empty, it means the input number was 0
    if result.is_empty() {
        result.push('0');
    } else {
        // Reverse the result string
        result = result.chars().rev().collect();
    }

    result
}

/// Converts a number string from its original base to a target base
///
/// # Parameters
/// - `num_str` - The string containing the number and its base in the format "number(base)"
/// - `to_base` - The target base
///
/// # Returns
/// Returns the string representation in the target base
pub fn convert_base(num_str: &str, to_base: u32) -> String {
    // Split the input string to extract the number and its base
    let parts: Vec<&str> = num_str.split('(').collect();
    let number = parts[0];
    let from_base = parts[1].trim_end_matches(')').parse::<u32>().expect("Invalid base");

    // Convert the number string from its original base to decimal
    let num_in_decimal = u32::from_str_radix(number, from_base).expect("Invalid number");

    // Convert the decimal number to the target base
    convert_to_base(num_in_decimal, to_base)
}